<template>
  <div id="Article">
    <el-backtop :bottom="60"></el-backtop>
    <div class="aaa" style="overflow: hidden;padding: 15px">
      <div class="title">
        <div class="left"><h2 v-html="articleList.title"></h2></div>
        <div class="right">
          <div class="right">
            <svg class="menuIcon icon" aria-hidden="true">
              <use xlink:href="#iconbusiness-career-office-verify-secure-protect-work-edcbf"></use>
            </svg>举报
          </div>
          <div class="right" @click="favour" v-if="!article.isFavour">
            <svg class="menuIcon icon" aria-hidden="true">
              <use xlink:href="#iconshoucang"></use>
            </svg>收藏
          </div>
          <div class="right" @click="nofavour" v-else>
            <svg class="menuIcon icon" aria-hidden="true">
              <use xlink:href="#iconshoucangchenggong"></use>
            </svg>已收藏
          </div>
        </div>
      </div>
      <div class="type">
        <div class="left">
          <i class="iconfont icontouxiang"></i>&nbsp;{{articleList.specialist.specialistName}}&nbsp;&nbsp;&nbsp;&nbsp;分类：{{articleList.area.area}}&nbsp;&nbsp;&nbsp;&nbsp;浏览：{{articleList.views}}
        </div>
        <div class="right">发布时间：{{articleList.releaseDateStr}}</div>
      </div>
      <div class="context" style="white-space: pre-wrap;" v-html="articleList.content"></div>
      <div class="context_footer">
        <div class="context_footer" v-if="!article.isHug" @click="baobao">
          <svg class="menuIcon icon" aria-hidden="true">
            <use xlink:href="#iconshouye-kuqi"></use>
          </svg>抱抱
        </div>
        <div class="context_footer" v-else>
          <svg class="menuIcon icon" aria-hidden="true">
            <use xlink:href="#iconemoji-keai"></use>
          </svg>已抱抱
        </div>
        <div class="context_footer" v-if="!article.isThumbsDown" @click="caicai">
          <svg class="menuIcon icon" aria-hidden="true">
            <use xlink:href="#iconchaping"></use>
          </svg>踩踩
        </div>
        <div class="context_footer" v-else>
          <svg class="menuIcon icon" aria-hidden="true">
            <use xlink:href="#iconcai-mian"></use>
          </svg>已踩
        </div>
      </div>
      <br>
      <el-input type="textarea"></el-input>
      <div class="commar"><el-button type="primary">提交</el-button></div>
    </div>
  </div>
</template>

<script>
  export default {
    name: "Article",
    data() {
      return {
        article: {},
        articleList: {
          area: {},
          specialist: {}
        }
      }
    },
    mounted() {
      console.log(this.$route.params.aid);
      let uid
      if (this.$store.state.user.uid==='')
        uid = null
      else uid = this.$store.state.user.uid
      this.$http({
        url: '/article/findArticleById/'+this.$route.params.aid+'/'+uid,
        method: 'post',
      }).then(res => {
        console.log(res.data);
        this.article = res.data
        this.articleList = res.data.articleList
        console.log(this.article);
      }).catch(err => {})
    },
    methods: {
      //点击收藏
      favour() {
        if (this.$store.state.user.uid === ''){
          this.$message.error('请先登录');
        }else {
          let uid = this.$store.state.user.uid
          this.$http({
            method: 'post',
            url: '/user/collect/'+uid+'/'+this.articleList.aid
          }).then(res => {
            this.article.isFavour = !this.article.isFavour
          }).catch(err => {
            console.log(err);
          })
        }
      },
      //取消收藏
      nofavour(){
        let uid = this.$store.state.user.uid
        this.$http({
          method: 'post',
          url: '/user/deleteFavour/'+uid+'/'+this.articleList.aid
        }).then(res => {
          this.article.isFavour = !this.article.isFavour
        }).catch(err => {
          console.log(err);
        })
      },
      //踩踩
      caicai(){
        if (this.$store.state.user.uid === ''){
          this.$message.error('请先登录');
        }else {
          let uid = this.$store.state.user.uid
          this.$http({
            method: 'post',
            url: '/user/thumbsdown/'+uid+'/'+this.articleList.aid
          }).then(res => {
            this.article.isThumbsDown = !this.article.isThumbsDown
          }).catch(err => {
            console.log(err);
          })
        }
      },
      //抱抱
      baobao(){
        if (this.$store.state.user.uid === ''){
          this.$message.error('请先登录');
        }else {
          let uid = this.$store.state.user.uid
          this.$http({
            method: 'post',
            url: '/user/hug/'+uid+'/'+this.articleList.aid
          }).then(res => {
            this.article.isHug = !this.article.isHug
          }).catch(err => {
            console.log(err);
          })
        }
      }
    }
  }
</script>

<style scoped>
  .menuIcon{
    font-size: 16px;
    width: 30px;
    height: 20px;
  }
  #Article{
    width: 900px;
    margin: 40px auto;
    background-color: #ffffff;
    -webkit-box-shadow: 0 2px 10px 0 rgba(0, 0, 0, 0.1);
    box-shadow: 0 2px 10px 0 rgba(0, 0, 0, 0.1);
  }
  .title, .type{
    width: 100%;
    overflow: hidden;
  }
  .type{
    margin-top: 10px;
  }
  .left{
    float: left;
  }
  .left h2{
    margin: 0;
    color: #5f9ea0;
  }
  .right{
    float: right;
    color: #5f9ea0;
  }
  .type div{
    font-size: 16px;
    color: #c0c0c0;
  }
  .context{
    margin: 10px 0;
    line-height: 1.5;
    color: #696969;
  }
  .context_footer{
    float: right;
    margin: 20px 0;
    color: #5f9ea0;
  }
  .commar{
    float: right;
    margin: 3px;
  }
</style>
